var question_detail = new Vue({
    el: "#question_detail",
    data:{
        questionUrl:"api/sys/question/detail?id=",
        apiMessageUrl: "api/sys/msg/send",
        menuUrl: "api/sys/index/menuCol",
        menuData:{},
        question:{},
        msg: {
            name: "",
            phone: "",
            remarks: ""
        },
        id:""
    },
    mounted:function () {
        this.setPageType();//获取当前链接类型
        this.getInfoContent();
        menu_hover();
    },
    methods: {
        setPageType:function(){
            this.id = this.getQueryString('id');
        },
        getQueryString:function (name) {//获取链接 参数
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        },
        getInfoContent:function () {
            this.$http.get(baseUrl + this.questionUrl + this.id).then(
                function (res) {
                    this.question = res.data.data;
                    this.question.answer = this.question.answer.replace(new RegExp("\n",'g'),"<br/>");
                }
            ).catch(function (response) {
                console.log(response)
            })

            this.$http.get(baseUrl + this.menuUrl).then(
                function (res) {
                    this.menuData = res.data.data;
                }
            ).catch(function (response) {
                console.log(response)
            })
        },
        sendMsg: function () {
            for(key in this.msg){
                if(!this.msg[key]){
                    console.log(1);
                    return;
                }
            }
            this.$http.post(baseUrl + this.apiMessageUrl, this.msg).then(function (res) {
                this.clearOldMsg();
            }).catch(function (response) {
                console.log(response)
            })
        },
        clearOldMsg: function () {
            this.msg = {
                name: "",
                phone: "",
                remarks: ""
            }
        }
    }
})